package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SpZubie;
import com.ruoyi.system.service.ISpZubieService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 组别Controller
 * 
 * @author ruoyi
 * @date 2022-11-10
 */
@RestController
@RequestMapping("/system/zubie")
public class SpZubieController extends BaseController
{
    @Autowired
    private ISpZubieService spZubieService;

    /**
     * 查询组别列表
     */
    @PreAuthorize("@ss.hasPermi('system:zubie:list')")
    @GetMapping("/list")
    public TableDataInfo list(SpZubie spZubie)
    {
        startPage();
        List<SpZubie> list = spZubieService.selectSpZubieList(spZubie);
        return getDataTable(list);
    }

    /**
     * 导出组别列表
     */
    @PreAuthorize("@ss.hasPermi('system:zubie:export')")
    @Log(title = "组别", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SpZubie spZubie)
    {
        List<SpZubie> list = spZubieService.selectSpZubieList(spZubie);
        ExcelUtil<SpZubie> util = new ExcelUtil<SpZubie>(SpZubie.class);
        util.exportExcel(response, list, "组别数据");
    }

    /**
     * 获取组别详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:zubie:query')")
    @GetMapping(value = "/{zbId}")
    public AjaxResult getInfo(@PathVariable("zbId") Long zbId)
    {
        return AjaxResult.success(spZubieService.selectSpZubieByZbId(zbId));
    }

    /**
     * 新增组别
     */
    @PreAuthorize("@ss.hasPermi('system:zubie:add')")
    @Log(title = "组别", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SpZubie spZubie)
    {
        return toAjax(spZubieService.insertSpZubie(spZubie));
    }

    /**
     * 修改组别
     */
    @PreAuthorize("@ss.hasPermi('system:zubie:edit')")
    @Log(title = "组别", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SpZubie spZubie)
    {
        return toAjax(spZubieService.updateSpZubie(spZubie));
    }

    /**
     * 删除组别
     */
    @PreAuthorize("@ss.hasPermi('system:zubie:remove')")
    @Log(title = "组别", businessType = BusinessType.DELETE)
	@DeleteMapping("/{zbIds}")
    public AjaxResult remove(@PathVariable Long[] zbIds)
    {
        return toAjax(spZubieService.deleteSpZubieByZbIds(zbIds));
    }
}
